/*
 * 项目名称:keel-flower
 * 类名称:JacksonConfiguration.java
 * 包名称:me.keelflower.configuration
 *
 * 修改履历:
 *      日期                修正者      主要内容
 *      2021/5/12 16:32    liliudong      初版完成
 *
 */
package com.liliudong.keelflower.common.core.config;

import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Jackson配置类
 *
 * @author liliudong 2021/5/12 16:32
 */
@Configuration
public class JacksonConfiguration {

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        return jacksonObjectMapperBuilder -> {
            // 包装类Long和基本数据long类型到前端转换成String
            jacksonObjectMapperBuilder.serializerByType(Long.class, ToStringSerializer.instance);
            jacksonObjectMapperBuilder.serializerByType(Long.TYPE, ToStringSerializer.instance);
        };
    }
}
